package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;

import java.time.LocalDateTime;
import java.util.List;

public class StudentServcieImpl implements StudentService {
    private StudentMapper studentMapper;
    @Override
    public void save(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.insert(student);
    }

    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());

        studentMapper.update(student);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Integer educationId, String number, Integer classId) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

       /* //2. 执行查询
        List<Emp> empList = empMapper.list(name,educationId,number,classId);
        Page<Emp> p = (Page<Emp>) empList;*/
        List<Student> studentList =studentMapper.list(name,educationId,number,classId);
        Page<Student> p=(Page<Student>)studentList;


        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void dealDiscipline(Student student) {
        studentMapper.dealDiscipline(student);
    }
}
